In [1]:
import pandas as pd #Data manipulation
import numpy as np #Numerics
import statsmodels.api as sm #Statistical
import matplotlib.pyplot as plt #Embedded plotting
from pandas.stats.api import ols
#from statsmodels.regression.linear_model import WLS
import warnings
warnings.filterwarnings('ignore')
data = pd.read_json("OverwatchTotal.json")
In [2]:
data = data[pd.notnull(data['rank'])]
len(data)
Out[2]:
In [3]:
rank = [x for x in data['rank']]
level = [x for x in data['level']]
comp = [x for x in data.get('comp', {})]
qp = [x for x in data.get('qp', {})]
heroes = [x for x in data.get('heroes', {})]
[len(rank), len(level), len(comp), len(qp), len(heroes)]
Out[3]:
In [4]:
def getCompWins(x):
b = x.get('total', {})
return(b.get('wins', {}))
def getWinRate(x):
b = x.get('total', {})
return(b.get('rate', {}))
def getAvgElims(x):
b = x.get('average', {})
return(b.get('elims', {}))
def getTotalElims(x):
b = x.get('total', {})
return(b.get('elims', {}))
def getMostElims(x):
b = x.get('most', {})
return(b.get('elims', {}))
def getGames(x):
b = x.get('total',{})
return(b.get('games',{}))
def getAna(x):
b = x.get('playtime',{})
return(b.get('ana',{}))
def getBastion(x):
b = x.get('playtime',{})
return(b.get('bastion',{}))
def getDva(x):
b = x.get('playtime',{})
return(b.get('dva',{}))
def getGenji(x):
b = x.get('playtime',{})
return(b.get('genji',{}))
def getHanzo(x):
b = x.get('playtime',{})
return(b.get('hanzo',{}))
def getJunkrat(x):
b = x.get('playtime',{})
return(b.get('junkrat',{}))
def getLucio(x):
b = x.get('playtime',{})
return(b.get('lucio',{}))
def getMccree(x):
b = x.get('playtime',{})
return(b.get('mccree',{}))
def getMei(x):
b = x.get('playtime',{})
return(b.get('mei',{}))
def getMercy(x):
b = x.get('playtime',{})
return(b.get('mercy',{}))
def getOrisa(x):
b = x.get('playtime',{})
return(b.get('orisa',{}))
def getPharah(x):
b = x.get('playtime',{})
return(b.get('pharah',{}))
def getReaper(x):
b = x.get('playtime',{})
return(b.get('reaper',{}))
def getReinhardt(x):
b = x.get('playtime',{})
return(b.get('reinhardt',{}))
def getRoadhog(x):
b = x.get('playtime',{})
return(b.get('roadhog',{}))
def getSoldier76(x):
b = x.get('playtime',{})
return(b.get('soldier76',{}))
def getSombra(x):
b = x.get('playtime',{})
return(b.get('sombra',{}))
def getSymmetra(x):
b = x.get('playtime',{})
return(b.get('symmetra',{}))
def getTorbjorn(x):
b = x.get('playtime',{})
return(b.get('torbjorn',{}))
def getTracer(x):
b = x.get('playtime',{})
return(b.get('tracer',{}))
def getWidowmaker(x):
b = x.get('playtime',{})
return(b.get('widowmaker',{}))
def getWinston(x):
b = x.get('playtime',{})
return(b.get('winston',{}))
def getZarya(x):
b = x.get('playtime',{})
return(b.get('zarya',{}))
def getZenyatta(x):
b = x.get('playtime',{})
return(b.get('zenyatta',{}))
def filterNaN(x):
if x < 1e100:
return(x)
else:
return(0)
def filterLowRank(x):
if x > 0 and x < 1666:
return(x)
else:
return(0)
def filterMedRank(x):
if x > 1666 and x < 3332:
return(x)
else:
return(0)
def filterHighRank(x):
if x > 3332 and x < 5001:
return(x)
else:
return(0)
def filterFloats(x):
if type(x) == float:
return(x)
else:
return(0)
def filterInts(x):
if type(x) == int:
return(x)
else:
return(0)
In [5]:
compWins = [getCompWins(x) for x in comp]
qpGames = [getGames(x) for x in qp]
anaHours = [getAna(x) for x in heroes]
bastionHours = [getBastion(x) for x in heroes]
dvaHours = [getDva(x) for x in heroes]
genjiHours = [getGenji(x) for x in heroes]
hanzoHours = [getHanzo(x) for x in heroes]
junkratHours = [getJunkrat(x) for x in heroes]
lucioHours = [getLucio(x) for x in heroes]
mccreeHours = [getMccree(x) for x in heroes]
meiHours = [getMei(x) for x in heroes]
mercyHours = [getMercy(x) for x in heroes]
orisaHours = [getOrisa(x) for x in heroes]
pharahHours = [getPharah(x) for x in heroes]
reaperHours = [getReaper(x) for x in heroes]
reinhardtHours = [getReinhardt(x) for x in heroes]
roadhogHours = [getRoadhog(x) for x in heroes]
soldier76Hours = [getSoldier76(x) for x in heroes]
sombraHours = [getSombra(x) for x in heroes]
symmetraHours = [getSymmetra(x) for x in heroes]
torbjornHours = [getTorbjorn(x) for x in heroes]
tracerHours = [getTracer(x) for x in heroes]
widowmakerHours = [getWidowmaker(x) for x in heroes]
winstonHours = [getWinston(x) for x in heroes]
zaryaHours = [getZarya(x) for x in heroes]
zenyattaHours = [getZenyatta(x) for x in heroes]
rank=[filterNaN(x) for x in rank]
levelFiltered= [filterNaN(x) for x in level]
lowRank = [filterLowRank(x) for x in rank]
medRank = [filterMedRank(x) for x in rank]
highRank = [filterHighRank(x) for x in rank]
avg = [getAvgElims(x) for x in comp]
total = [getTotalElims(x) for x in comp]
most = [getMostElims(x) for x in comp]
avgElims = [filterFloats(x) for x in avg]
totalElims = [filterInts(x) for x in total]
mostElims = [filterInts(x) for x in most]
winRate = [getWinRate(x) for x in comp]
In [6]:
df = pd.DataFrame({"Rank": rank, "Level": level, "Comp Wins": compWins, "Quick Games": qpGames, "Ana": anaHours, "Bastion": bastionHours, "D.Va": dvaHours, "Genji": genjiHours, "Hanzo": hanzoHours, "Junkrat": junkratHours, "Lucio": lucioHours, "McCree": mccreeHours, "Mei": meiHours, "Mercy": mercyHours, "Orisa": orisaHours, "Pharah": pharahHours, "Reaper": reaperHours, "Reinhardt": reinhardtHours, "Roadhog": roadhogHours, "Soldier76": soldier76Hours, "Sombra": sombraHours, "Symmetra": symmetraHours, "Torbjorn": torbjornHours, "Tracer": tracerHours, "Widowmaker": widowmakerHours, "Winston": winstonHours, "Zarya": zaryaHours, "Zenyatta": zenyattaHours})
res = ols(y = df['Rank'], x = df[['Level','Comp Wins', 'Quick Games', 'Ana', 'Bastion', 'D.Va', 'Genji', 'Hanzo', 'Junkrat', 'Lucio', 'McCree', 'Mei', 'Mercy', 'Orisa', 'Pharah', 'Reaper', 'Reinhardt', 'Roadhog', 'Soldier76', 'Sombra', 'Symmetra', 'Torbjorn', 'Tracer', 'Widowmaker', 'Winston', 'Zarya', 'Zenyatta']])
res
Out[6]:
In [41]:
import matplotlib.pyplot as plt
%matplotlib inline
f=plt.figure(figsize=(20,9))
# bar = plt.bar(rank, avgElims)
plt.hist(rank, 200)
#plt.plot(rank)
plt.show()
# bar
# plt.show(bar)
$Y=\beta_0 +\beta_1x_1+\beta_2x_2 + \cdots + \beta_n x_n$
In [7]:
df = pd.DataFrame({"Rank": rank, "Level": level, "Comp Wins": compWins, "Quick Games": qpGames, "Ana": anaHours, "Bastion": bastionHours, "D.Va": dvaHours, "Genji": genjiHours, "Hanzo": hanzoHours, "Junkrat": junkratHours, "Lucio": lucioHours, "McCree": mccreeHours, "Mei": meiHours, "Mercy": mercyHours, "Orisa": orisaHours, "Pharah": pharahHours, "Reaper": reaperHours, "Reinhardt": reinhardtHours, "Roadhog": roadhogHours, "Soldier76": soldier76Hours, "Sombra": sombraHours, "Symmetra": symmetraHours, "Torbjorn": torbjornHours, "Tracer": tracerHours, "Widowmaker": widowmakerHours, "Winston": winstonHours, "Zarya": zaryaHours, "Zenyatta": zenyattaHours})
res = ols(y = df['Rank'], x = df[['Level','Comp Wins', 'Quick Games', 'Ana', 'Bastion', 'D.Va', 'Genji', 'Hanzo', 'Junkrat', 'Lucio', 'McCree', 'Mei', 'Mercy', 'Orisa', 'Pharah', 'Reaper', 'Reinhardt', 'Roadhog', 'Soldier76', 'Sombra', 'Symmetra', 'Torbjorn', 'Tracer', 'Widowmaker', 'Winston', 'Zarya', 'Zenyatta']])
res
Out[7]:
In [8]:
df = pd.DataFrame({"Rank": rank, "Comp Wins": compWins, "Ana": anaHours, "Bastion": bastionHours, "D.Va": dvaHours, "Genji": genjiHours, "Hanzo": hanzoHours, "Junkrat": junkratHours, "Lucio": lucioHours, "McCree": mccreeHours, "Mei": meiHours, "Mercy": mercyHours, "Pharah": pharahHours, "Reaper": reaperHours, "Reinhardt": reinhardtHours, "Roadhog": roadhogHours, "Soldier76": soldier76Hours, "Sombra": sombraHours, "Symmetra": symmetraHours, "Torbjorn": torbjornHours, "Tracer": tracerHours, "Widowmaker": widowmakerHours, "Winston": winstonHours, "Zarya": zaryaHours, "Zenyatta": zenyattaHours})
res = ols(y = df['Rank'], x = df[['Comp Wins', 'Ana', 'Bastion', 'D.Va', 'Genji', 'Hanzo', 'Junkrat', 'Lucio', 'McCree', 'Mei', 'Mercy', 'Pharah', 'Reaper', 'Reinhardt', 'Roadhog', 'Soldier76', 'Sombra', 'Symmetra', 'Torbjorn', 'Tracer', 'Widowmaker', 'Winston', 'Zarya', 'Zenyatta']])
res
Out[8]:
$Y=\beta_0 +\beta_1x_1+\beta_2x_2 + \cdots + \beta_n x_n$
In [9]:
df = pd.DataFrame({"Rank": lowRank, "Comp Wins": compWins, "Ana": anaHours, "Bastion": bastionHours, "D.Va": dvaHours, "Genji": genjiHours, "Hanzo": hanzoHours, "Junkrat": junkratHours, "Lucio": lucioHours, "McCree": mccreeHours, "Mei": meiHours, "Mercy": mercyHours, "Pharah": pharahHours, "Reaper": reaperHours, "Reinhardt": reinhardtHours, "Roadhog": roadhogHours, "Soldier76": soldier76Hours, "Sombra": sombraHours, "Symmetra": symmetraHours, "Torbjorn": torbjornHours, "Tracer": tracerHours, "Widowmaker": widowmakerHours, "Winston": winstonHours, "Zarya": zaryaHours, "Zenyatta": zenyattaHours})
res = ols(y = df['Rank'], x = df[['Comp Wins', 'Ana', 'Bastion', 'D.Va', 'Genji', 'Hanzo', 'Junkrat', 'Lucio', 'McCree', 'Mei', 'Mercy', 'Pharah', 'Reaper', 'Reinhardt', 'Roadhog', 'Soldier76', 'Sombra', 'Symmetra', 'Torbjorn', 'Tracer', 'Widowmaker', 'Winston', 'Zarya', 'Zenyatta']])
res
Out[9]:
$Y=\beta_0 +\beta_1x_1+\beta_2x_2 + \cdots + \beta_n x_n$
In [10]:
df = pd.DataFrame({"Rank": medRank, "Comp Wins": compWins, "Ana": anaHours, "Bastion": bastionHours, "D.Va": dvaHours, "Genji": genjiHours, "Hanzo": hanzoHours, "Junkrat": junkratHours, "Lucio": lucioHours, "McCree": mccreeHours, "Mei": meiHours, "Mercy": mercyHours, "Pharah": pharahHours, "Reaper": reaperHours, "Reinhardt": reinhardtHours, "Roadhog": roadhogHours, "Soldier76": soldier76Hours, "Sombra": sombraHours, "Symmetra": symmetraHours, "Torbjorn": torbjornHours, "Tracer": tracerHours, "Widowmaker": widowmakerHours, "Winston": winstonHours, "Zarya": zaryaHours, "Zenyatta": zenyattaHours})
res = ols(y = df['Rank'], x = df[['Comp Wins', 'Ana', 'Bastion', 'D.Va', 'Genji', 'Hanzo', 'Junkrat', 'Lucio', 'McCree', 'Mei', 'Mercy', 'Pharah', 'Reaper', 'Reinhardt', 'Roadhog', 'Soldier76', 'Sombra', 'Symmetra', 'Torbjorn', 'Tracer', 'Widowmaker', 'Winston', 'Zarya', 'Zenyatta']])
res
Out[10]:
$Y=\beta_0 +\beta_1x_1+\beta_2x_2 + \cdots + \beta_n x_n$
In [11]:
df = pd.DataFrame({"Rank": highRank, "Comp Wins": compWins, "Ana": anaHours, "Bastion": bastionHours, "D.Va": dvaHours, "Genji": genjiHours, "Hanzo": hanzoHours, "Junkrat": junkratHours, "Lucio": lucioHours, "McCree": mccreeHours, "Mei": meiHours, "Mercy": mercyHours, "Pharah": pharahHours, "Reaper": reaperHours, "Reinhardt": reinhardtHours, "Roadhog": roadhogHours, "Soldier76": soldier76Hours, "Sombra": sombraHours, "Symmetra": symmetraHours, "Torbjorn": torbjornHours, "Tracer": tracerHours, "Widowmaker": widowmakerHours, "Winston": winstonHours, "Zarya": zaryaHours, "Zenyatta": zenyattaHours})
res = ols(y = df['Rank'], x = df[['Comp Wins', 'Ana', 'Bastion', 'D.Va', 'Genji', 'Hanzo', 'Junkrat', 'Lucio', 'McCree', 'Mei', 'Mercy', 'Pharah', 'Reaper', 'Reinhardt', 'Roadhog', 'Soldier76', 'Sombra', 'Symmetra', 'Torbjorn', 'Tracer', 'Widowmaker', 'Winston', 'Zarya', 'Zenyatta']])
res
Out[11]:
$Y=\beta_0 +\beta_1x_1+\beta_2x_2 + \cdots + \beta_n x_n$
In [12]:
df = pd.DataFrame({"Rank": rank, "Avg Elims": avgElims, "Total Elims": totalElims, "Most Elims": mostElims})
res = ols(y = df['Rank'], x = df[['Avg Elims', 'Total Elims', 'Most Elims']])
res
Out[12]:
$Y=\beta_0 +\beta_1x_1+\beta_2x_2 + \cdots + \beta_n x_n$
In [13]:
df = pd.DataFrame({"Avg Elims": avgElims, "Genji": genjiHours, "McCree": mccreeHours, "Pharah": pharahHours, "Reaper": reaperHours, "Soldier76": soldier76Hours, "Sombra": sombraHours, "Tracer": tracerHours})
res = ols(y = df['Avg Elims'], x = df[['Genji', 'McCree', 'Pharah', 'Reaper', 'Soldier76', 'Sombra', 'Tracer']])
res
Out[13]:
$Y=\beta_0 +\beta_1x_1+\beta_2x_2 + \cdots + \beta_n x_n$
In [14]:
df = pd.DataFrame({"Avg Elims": avgElims, "Bastion": bastionHours, "Hanzo": hanzoHours, "Junkrat": junkratHours, "Mei": meiHours, "Torbjorn": torbjornHours, "Widowmaker": widowmakerHours, })
res = ols(y = df['Avg Elims'], x = df[['Bastion', 'Hanzo', 'Junkrat', 'Mei', 'Torbjorn', 'Widowmaker']])
res
Out[14]:
$Y=\beta_0 +\beta_1x_1+\beta_2x_2 + \cdots \beta_n x_n$
In [15]:
df = pd.DataFrame({"Avg Elims": avgElims, "D.Va": dvaHours, "Reinhardt": reinhardtHours, "Roadhog": roadhogHours, "Winston": winstonHours, "Zarya": zaryaHours})
res = ols(y = df['Avg Elims'], x = df[['D.Va', 'Reinhardt', 'Roadhog', 'Winston', 'Zarya']])
res
Out[15]:
$Y=\beta_0 +\beta_1x_1+\beta_2x_2 + \cdots \beta_n x_n$
In [16]:
df = pd.DataFrame({"Avg Elims": avgElims, "Ana": anaHours, "Lucio": lucioHours, "Mercy": mercyHours, "Symmetra": symmetraHours, "Zenyatta": zenyattaHours})
res = ols(y = df['Avg Elims'], x = df[['Ana', 'Lucio', 'Mercy', 'Symmetra', 'Zenyatta']])
res
Out[16]:
$Y=\beta_0 +\beta_1x_1+\beta_2x_2 + \cdots \beta_n x_n$
$Y=\beta_0 +\beta_1x_1+\beta_2x_2 + \cdots \beta_n x_n$
In [17]:
df = pd.DataFrame({"Rank": rank, "Ana": anaHours})
res = ols(y = df['Rank'], x = df[['Ana']])
res
Out[17]:
$Y=\beta_0 +\beta_1x_1+\beta_2x_2 + \cdots \beta_n x_n$
In [18]:
df = pd.DataFrame({"Rank": rank, "Bastion": bastionHours})
res = ols(y = df['Rank'], x = df[['Bastion']])
res
Out[18]:
In [19]:
df = pd.DataFrame({"Rank": rank, "D.Va": dvaHours})
res = ols(y = df['Rank'], x = df[['D.Va']])
res
Out[19]:
In [20]:
df = pd.DataFrame({"Rank": rank, "Genji": genjiHours})
res = ols(y = df['Rank'], x = df[['Genji']])
res
Out[20]:
In [21]:
df = pd.DataFrame({"Rank": rank, "Hanzo": hanzoHours})
res = ols(y = df['Rank'], x = df[['Hanzo']])
res
Out[21]:
In [22]:
df = pd.DataFrame({"Rank": rank, "Junkrat": junkratHours})
res = ols(y = df['Rank'], x = df[['Junkrat']])
res
Out[22]:
In [23]:
df = pd.DataFrame({"Rank": rank, "Lucio": lucioHours})
res = ols(y = df['Rank'], x = df[['Lucio']])
res
Out[23]:
In [24]:
df = pd.DataFrame({"Rank": rank, "McCree": mccreeHours})
res = ols(y = df['Rank'], x = df[['McCree']])
res
Out[24]:
In [25]:
df = pd.DataFrame({"Rank": rank, "Mei": meiHours})
res = ols(y = df['Rank'], x = df[['Mei']])
res
Out[25]:
In [26]:
df = pd.DataFrame({"Rank": rank, "Mercy": mercyHours})
res = ols(y = df['Rank'], x = df[['Mercy']])
res
Out[26]:
In [27]:
df = pd.DataFrame({"Rank": rank, "Orisa": orisaHours})
res = ols(y = df['Rank'], x = df[['Orisa']])
res
Out[27]:
In [28]:
df = pd.DataFrame({"Rank": rank, "Pharah": pharahHours})
res = ols(y = df['Rank'], x = df[['Pharah']])
res
Out[28]:
In [29]:
df = pd.DataFrame({"Rank": rank, "Reaper": reaperHours})
res = ols(y = df['Rank'], x = df[['Reaper']])
res
Out[29]:
In [30]:
df = pd.DataFrame({"Rank": rank, "Reinhardt": reinhardtHours})
res = ols(y = df['Rank'], x = df[['Reinhardt']])
res
Out[30]:
In [31]:
df = pd.DataFrame({"Rank": rank, "Roadhog": roadhogHours})
res = ols(y = df['Rank'], x = df[['Roadhog']])
res
Out[31]:
In [32]:
df = pd.DataFrame({"Rank": rank, "Soldier76": soldier76Hours})
res = ols(y = df['Rank'], x = df[['Soldier76']])
res
Out[32]:
In [33]:
df = pd.DataFrame({"Rank": rank, "Sombra": sombraHours})
res = ols(y = df['Rank'], x = df[['Sombra']])
res
Out[33]:
In [34]:
df = pd.DataFrame({"Rank": rank, "Symmetra": symmetraHours})
res = ols(y = df['Rank'], x = df[['Symmetra']])
res
Out[34]:
In [35]:
df = pd.DataFrame({"Rank": rank, "Torbjorn": torbjornHours})
res = ols(y = df['Rank'], x = df[['Torbjorn']])
res
Out[35]:
In [36]:
df = pd.DataFrame({"Rank": rank, "Tracer": tracerHours})
res = ols(y = df['Rank'], x = df[['Tracer']])
res
Out[36]:
In [37]:
df = pd.DataFrame({"Rank": rank, "Widowmaker": widowmakerHours})
res = ols(y = df['Rank'], x = df[['Widowmaker']])
res
Out[37]:
In [38]:
df = pd.DataFrame({"Rank": rank, "Winston": winstonHours})
res = ols(y = df['Rank'], x = df[['Winston']])
res
Out[38]:
In [39]:
df = pd.DataFrame({"Rank": rank, "Zarya": zaryaHours})
res = ols(y = df['Rank'], x = df[['Zarya']])
res
Out[39]:
In [40]:
df = pd.DataFrame({"Rank": rank, "Zenyatta": zenyattaHours})
res = ols(y = df['Rank'], x = df[['Zenyatta']])
res
Out[40]:
In [41]:
import matplotlib.pyplot as plt
%matplotlib inline
f=plt.figure(figsize=(20,9))
# bar = plt.bar(rank, avgElims)
plt.hist(rank, 200)
#plt.plot(rank)
plt.show()
# bar
# plt.show(bar)
In [43]:
zeros = [x for x in rank if x >= 0 and x <= 100]
zeros
Out[43]: